package jok.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInputStreamDemo {

	public static void main(String[] args) {
		FileWriterDemo.writeFile3();

		// readFile();
		readFile2();

		FileDemo.deleteFile("D:\\a.txt");
	}

	public static void readFile() {
		FileInputStream fis = null;
		try {
			fis = new FileInputStream("D:/a.txt");
			int num = -1;
			while ((num = fis.read()) != -1) {
				System.out.print((char) num);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (fis != null)
					fis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void readFile2() {
		FileInputStream fis = null;
		try {
			fis = new FileInputStream("D:/a.txt");
			int num = -1;
			byte[] bs = new byte[1024];
			while ((num = fis.read(bs)) != -1) {
				System.out.print(new String(bs, 0, num));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (fis != null)
					fis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
